主题
设置OCR模型推理配置 - OcrSetModelConfig
函数简介
对已加载 OCR 模型局部合并更新推理调参(JSON 中出现的字段才更新)。成功后会重新初始化该句柄对应后端,不会重新解密或读盘。
键名大小写不敏感;布尔/数值支持字符串形式。规则见 JSON配置解析约定。单键修改可用 OcrSetModelConfigByKey。
接口名称
OcrSetModelConfigDLL 调用
int OcrSetModelConfig(long ola, long modelHandle, string configJson);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug 对象指针 |
| modelHandle | 长整数型 | 模型句柄;内置 mobile 为 0 |
| configJson | 字符串 | UTF-8 JSON 对象;键名为 PascalCase(大小写不敏感) |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.OcrSetModelConfig(0, "value");
if (ret == 1) {
// 操作成功
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.OcrSetModelConfig(0, "value");
if (ret == 1)
{
// 操作成功
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.OcrSetModelConfig(0, "value")
if ret == 1:
pass # 操作成功java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.OcrSetModelConfig(0, "value");
if (ret == 1) {
// 操作成功
}cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.OcrSetModelConfig(0, "value")
if(ret == 1) {
// 操作成功
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.OcrSetModelConfig(0, "value")
If ret = 1 Then
' 操作成功
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.OcrSetModelConfig(0, “value”)
.如果真 (ret = 1)
' 操作成功
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.OcrSetModelConfig(0, "value");
if(ret == 1){
// 操作成功
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.OcrSetModelConfig(0, "value")
如果真 (ret = 1)
{
// 操作成功
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.OcrSetModelConfig(0, "value");
if (ret == 1) {
// 操作成功
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
OcrSetModelConfig(instance, 0, "value");csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int OcrSetModelConfig(long ola, long modelHandle, string configJson);
long instance = CreateCOLAPlugInterFace();
OcrSetModelConfig(instance, 0, "value");python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.OcrSetModelConfig(instance, 0, "value")返回值
整数型:1 成功;0 失败(句柄无效、JSON 非法或重初始化失败)。
注意事项
- 字段说明见 OCR模型配置说明。
- 不支持修改模型路径、密码、
BackendId等加载期参数,需重新 OcrLoadModel。 - 内置
modelHandle=0可直接 Set/Get;可通过OcrUseGpu/OcrGpuId切换 CPU/GPU,失败时回退 CPU。
